package com.ctshk.sapp.goods.controller;


import com.ctshk.common.annotations.OperationLogAnnotation;
import com.ctshk.common.dto.Result;
import com.ctshk.common.enums.OperationLogModel;
import com.ctshk.common.enums.OperationLogType;
import com.ctshk.common.model.PageResponse;
import com.ctshk.common.web.support.BaseController;
import com.ctshk.rpc.goods.dto.ShoppingShopStoreDTO;
import com.ctshk.rpc.goods.dto.ShoppingShopStoreDetailedTitleDTO;
import com.ctshk.rpc.goods.req.ShoppingShopStoreAddReq;
import com.ctshk.rpc.goods.req.ShoppingShopStorePageReq;
import com.ctshk.rpc.goods.req.ShoppingShopStoreUpdateStatusReq;
import com.ctshk.rpc.goods.service.IShoppingShopStoreService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * <p>
 * 小店管理 前端控制器
 * </p>
 *
 * @author 姜斌文
 * @since 2021-04-07
 */
@Api(value="小店管理", tags="小店管理")
@RestController
@RequestMapping("/shoppingShopStore/store")
public class ShoppingShopStoreController extends BaseController {

    @DubboReference
    private IShoppingShopStoreService shoppingShopStoreService;

    @ApiOperation(value = "新增小店", notes = "新增小店")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "新增小店", operDesc = "新增小店")
    @PostMapping("/addShoppingShopStore")
    public Result addShoppingShopStore(@RequestBody @Valid ShoppingShopStoreAddReq obj) {
    	shoppingShopStoreService.addShoppingShopStore(obj, getCurrentUser(getRequest()).getId());
        return Result.success();
    }

    @ApiOperation(value = "新增小店成员", notes = "新增小店成员")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.ADD, operTitle = "新增小店成员", operDesc = "新增小店成员")
    @PostMapping("/addShoppingShopStoreMember")
    public Result addShoppingShopStoreMember(@RequestBody @Valid ShoppingShopStoreAddReq obj) {
    	shoppingShopStoreService.addShoppingShopStoreMember(obj, getCurrentUser(getRequest()).getId());
        return Result.success();
    }
    
    @ApiOperation(value = "编辑小店", notes = "编辑小店")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "编辑小店", operDesc = "编辑小店")
    @PostMapping("/updateShoppingShopStore")
    public Result updateShoppingShopStore(@RequestBody @Valid ShoppingShopStoreAddReq obj) {
    	shoppingShopStoreService.updateShoppingShopStore(obj,getCurrentUser(getRequest()).getId());
        return Result.success();
    }
    
    @ApiOperation(value = "编辑小店状态", notes = "编辑小店状态")
    @OperationLogAnnotation(operModul = OperationLogModel.ORDER, operType = OperationLogType.UPDATE, operTitle = "编辑小店状态", operDesc = "编辑小店状态")
    @PostMapping("/updateShoppingShopStoreStatus")
    public Result updateShoppingShopStoreStatus(@RequestBody @Valid ShoppingShopStoreUpdateStatusReq obj) {
    	shoppingShopStoreService.updateShoppingShopStoreStatus(obj,getCurrentUser(getRequest()).getId());
        return Result.success();
    }
    

    @ApiOperation(value = "分页查询小店管理", notes = "分页查询小店管理")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "分页查询小店管理", operDesc = "分页查询小店管理")
    @PostMapping("/findPageList")
    public Result<PageResponse<ShoppingShopStoreDTO>> findPageList(@RequestBody ShoppingShopStorePageReq pageReq) {
        PageResponse<ShoppingShopStoreDTO> response = shoppingShopStoreService.findShoppingShopStoreByCondition(pageReq,getCurrentUser(getRequest()));
        return Result.success(response);
    }

    @ApiOperation(value = "小店詳情", notes = "小店詳情")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "小店詳情", operDesc = "小店詳情")
    @PostMapping("/findShoppingShopStoreDetailed")
    public Result<ShoppingShopStoreDetailedTitleDTO> findShoppingShopStoreDetailed(@RequestBody ShoppingShopStorePageReq pageReq) {
        ShoppingShopStoreDetailedTitleDTO response = shoppingShopStoreService.findShoppingShopStoreById(pageReq,getCurrentUser(getRequest()));
        return Result.success(response);
    }

    @ApiOperation(value = "根据ID查询小店详细信息", notes = "根据ID查询小店详细信息")
    @OperationLogAnnotation(operModul = OperationLogModel.SYSTEM, operType = OperationLogType.QUERY, operTitle = "小店詳情", operDesc = "小店詳情")
    @GetMapping("/findShoppingShopStoreDetailById/{id}")
    public Result<ShoppingShopStoreDTO> findShoppingShopStoreDetailById(@PathVariable("id") Long id) {
        ShoppingShopStoreDTO response = shoppingShopStoreService.findShoppingShopStoreDetailById(id,getCurrentUser(getRequest()));
        return Result.success(response);
    }
}
